package com.example.demo.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.service.AccessTokenService;

@RestController
public class AccessTokenController {

	protected final Logger logger= LoggerFactory.getLogger(getClass());
	
	@Autowired
	private AccessTokenService accessTokenService;
	
//	@Scheduled(cron = "0/2 * * * * ? ")
	@Scheduled(cron = "0 0 0/1 * * ? ")//每小时执行一次
	@GetMapping("getAccessToken")
	public Object getAccessToken() {
		Map<String,Object> resultMap = new HashMap<String, Object>();
		resultMap.put("message", "操作成功");
		try {
			accessTokenService.generateAccessToken();
			logger.info("更新微信accessToken成功");
		} catch (Exception e) {
			logger.info("更新微信accessToken失败");
			resultMap.put("message", "操作失败，"+e.getMessage());
		}
		return resultMap;
	}

}
